package implicits

import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
import upickle.default._

/**
 * Created by Administrator on 2019/11/11
 */

trait MyUJsonTool {

  implicit def dateTimeReadWrite: ReadWriter[DateTime] = {
    val pattern = "yyyy-MM-dd HH:mm:ss"
    readwriter[ujson.Str].bimap[DateTime](x => {
      ujson.Str(x.toString(pattern))
    }, y => {
      val formatter = DateTimeFormat.forPattern(pattern)
      formatter.parseDateTime(y.str)
    })
  }


}
